```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ存储结构详解 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight-box {
            border-left: 4px solid #4f46e5;
            background-color: rgba(79, 70, 229, 0.05);
        }
        .diagram-container {
            background-color: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.5rem;
        }
        .first-letter-lg::first-letter {
            font-size: 3em;
            float: left;
            line-height: 0.65;
            margin: 0.1em 0.2em 0 0;
            color: #4f46e5;
            font-weight: 700;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-2/3 md:pr-10">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">深入解析RocketMQ存储架构</h1>
                    <p class="text-xl text-indigo-100 mb-8">高性能分布式消息队列的核心存储设计与实现原理</p>
                    <div class="flex flex-wrap gap-4">
                        <div class="flex items-center bg-white bg-opacity-10 px-4 py-2 rounded-full">
                            <i class="fas fa-bolt text-yellow-300 mr-2"></i>
                            <span>高性能设计</span>
                        </div>
                        <div class="flex items-center bg-white bg-opacity-10 px-4 py-2 rounded-full">
                            <i class="fas fa-layer-group text-blue-200 mr-2"></i>
                            <span>多级存储结构</span>
                        </div>
                        <div class="flex items-center bg-white bg-opacity-10 px-4 py-2 rounded-full">
                            <i class="fas fa-search text-green-300 mr-2"></i>
                            <span>高效索引机制</span>
                        </div>
                    </div>
                </div>
                <div class="hidden md:block md:w-1/3 mt-10 md:mt-0">
                    <div class="bg-white bg-opacity-20 p-6 rounded-lg backdrop-filter backdrop-blur-sm">
                        <i class="fas fa-database text-6xl text-white opacity-80 mb-4 block text-center"></i>
                        <h3 class="text-lg font-semibold mb-2">核心存储组件</h3>
                        <ul class="text-indigo-100 space-y-1">
                            <li><i class="fas fa-arrow-right mr-2"></i>CommitLog</li>
                            <li><i class="fas fa-arrow-right mr-2"></i>ConsumeQueue</li>
                            <li><i class="fas fa-arrow-right mr-2"></i>IndexFile</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                <p class="text-lg text-gray-600 first-letter-lg">
                    RocketMQ采用了独特的存储架构，通过分离消息存储和索引，实现了高效的消息读写和查询能力。这种设计不仅提供了出色的性能，还保证了系统的高可用性和可扩展性，成为支撑大规模分布式系统的关键基础设施。
                </p>
            </div>
        </section>

        <!-- Physical Storage Structure -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-8 bg-indigo-600 mr-4 rounded-full"></div>
                <h2 class="text-3xl font-bold">物理存储结构</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <!-- CommitLog Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-indigo-100 p-4">
                        <i class="fas fa-file-alt text-indigo-600 text-2xl"></i>
                        <h3 class="text-xl font-semibold mt-2">CommitLog</h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>所有消息的主体内容存储</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>采用顺序写入方式，提高写入性能</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>每个文件默认1GB，文件名为起始偏移量</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>所有Topic消息混合存储</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- ConsumeQueue Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-purple-100 p-4">
                        <i class="fas fa-list-ol text-purple-600 text-2xl"></i>
                        <h3 class="text-xl font-semibold mt-2">ConsumeQueue</h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>消息的逻辑队列，CommitLog的索引</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>每个Topic的每个队列对应一个文件</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>存储路径: $HOME/store/consumequeue/{topic}/{queueId}</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>每个条目固定20字节</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- IndexFile Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-blue-100 p-4">
                        <i class="fas fa-search text-blue-600 text-2xl"></i>
                        <h3 class="text-xl font-semibold mt-2">IndexFile</h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>提供消息索引功能，支持Key和时间查询</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>采用哈希索引实现，默认500万哈希槽</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>每个IndexFile约400MB</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>索引文件名为创建时的时间戳</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Storage Diagram -->
            <div class="bg-white rounded-xl shadow-md p-6 mb-8">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-project-diagram text-indigo-500 mr-2"></i>
                    存储结构关系图
                </h3>
                <div class="diagram-container">
                    <div class="mermaid">
                        graph TD
                            A[生产者] -->|发送消息| B[Broker]
                            B -->|顺序写入| C[CommitLog]
                            C -->|异步构建| D[ConsumeQueue]
                            C -->|异步构建| E[IndexFile]
                            F[消费者] -->|拉取消息| B
                            D -->|提供索引| F
                            E -->|提供查询| F
                            style A fill:#4ade80,stroke:#333
                            style F fill:#60a5fa,stroke:#333
                            style B fill:#f59e0b,stroke:#333
                            style C fill:#818cf8,stroke:#333
                            style D fill:#a78bfa,stroke:#333
                            style E fill:#38bdf8,stroke:#333
                    </div>
                </div>
            </div>

            <!-- Data Flow Diagram -->
            <div class="bg-white rounded-xl shadow-md p-6">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-exchange-alt text-indigo-500 mr-2"></i>
                    数据流向示意图
                </h3>
                <div class="diagram-container">
                    <div class="mermaid">
                        sequenceDiagram
                            participant P as 生产者
                            participant B as Broker
                            participant C as CommitLog
                            participant Q as ConsumeQueue
                            participant I as IndexFile
                            participant Con as 消费者
                            
                            P->>B: 发送消息
                            B->>C: 顺序写入消息
                            activate C
                            C-->>B: 写入成功
                            B-->>P: 返回成功
                            deactivate C
                            
                            Note right of C: 异步构建索引
                            C->>Q: 构建ConsumeQueue
                            C->>I: 构建IndexFile
                            
                            Con->>B: 拉取消息
                            B->>Q: 查询消息索引
                            Q->>B: 返回索引信息
                            B->>C: 根据偏移量读取消息
                            C->>B: 返回消息内容
                            B->>Con: 返回消息
                    </div>
                </div>
            </div>
        </section>

        <!-- Logical Storage Structure -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-8 bg-indigo-600 mr-4 rounded-full"></div>
                <h2 class="text-3xl font-bold">逻辑存储结构</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <!-- Topic Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-green-100 p-4">
                        <i class="fas fa-tag text-green-600 text-2xl"></i>
                        <h3 class="text-xl font-semibold mt-2">Topic</h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-green-500 mt-2 mr-2"></i>
                                <span>消息的逻辑分类，一个Topic可以有多个队列</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-green-500 mt-2 mr-2"></i>
                                <span>物理上不对应具体文件或目录</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-green-500 mt-2 mr-2"></i>
                                <span>通过ConsumeQueue映射到CommitLog</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Queue Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-yellow-100 p-4">
                        <i class="fas fa-stream text-yellow-600 text-2xl"></i>
                        <h3 class="text-xl font-semibold mt-2">Queue</h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-yellow-500 mt-2 mr-2"></i>
                                <span>每个Topic包含多个队列，用于并行读写</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-yellow-500 mt-2 mr-2"></i>
                                <span>队列数量可配置，默认为4</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-yellow-500 mt-2 mr-2"></i>
                                <span>每个队列对应一组ConsumeQueue文件</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Message Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="bg-red-100 p-4">
                        <i class="fas fa-envelope text-red-600 text-2xl"></i>
                        <h3 class="text-xl font-semibold mt-2">Message</h3>
                    </div>
                    <div class="p-6">
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-red-500 mt-2 mr-2"></i>
                                <span>存储的基本单位</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-red-500 mt-2 mr-2"></i>
                                <span>包含消息ID、Topic、队列ID、消息体等</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-circle text-xs text-red-500 mt-2 mr-2"></i>
                                <span>在CommitLog中按照固定格式存储</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Message Format Diagram -->
            <div class="bg-white rounded-xl shadow-md p-6">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-file-code text-indigo-500 mr-2"></i>
                    CommitLog消息格式
                </h3>
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">字段</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">大小</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">说明</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">消息总长度</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">4字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">整个消息的总长度</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">魔数</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">4字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">Magic Code</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">CRC校验码</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">4字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息体CRC校验码</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">队列ID</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">4字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息队列ID</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">标志位</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">4字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息标志位</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">队列偏移量</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">8字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息在队列中的偏移量</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">存储时间戳</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">8字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息存储时间戳</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">消息体大小</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">8字节</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息体内容大小</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">消息体</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">变长</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息体内容</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">消息属性</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">变长</td>
                                <td class="px-6 py-4 text-sm text-gray-500">消息属性内容</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>

        <!-- CommitLog and ConsumeQueue Relationship -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-8 bg-indigo-600 mr-4 rounded-full"></div>
                <h2 class="text-3xl font-bold">CommitLog和ConsumeQueue的关系</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <!-- Design Advantages -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-star text-yellow-500 mr-2"></i>
                        设计优势
                    </h3>
                    <div class="space-y-4">
                        <div class="highlight-box p-4 rounded-r">
                            <h4 class="font-semibold text-indigo-600 mb-2">写入性能优化</h4>
                            <ul class="text-gray-600 space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>CommitLog采用顺序写入，避免随机写入的性能问题</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>所有Topic消息共用一个CommitLog，充分利用顺序写入优势</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>消息写入CommitLog即可返回成功，ConsumeQueue异步构建</span>
                                </li>
                            </ul>
                        </div>
                        <div class="highlight-box p-4 rounded-r">
                            <h4 class="font-semibold text-indigo-600 mb-2">读取性能优化</h4>
                            <ul class="text-gray-600 space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>ConsumeQueue条目小，易于缓存在内存中</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>消费者可快速定位消息在CommitLog中的位置</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>支持批量读取，提高读取效率</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Implementation Details -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-cogs text-blue-500 mr-2"></i>
                        实现细节
                    </h3>
                    <div class="space-y-6">
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">ConsumeQueue条目格式</h4>
                            <div class="bg-gray-50 p-4 rounded-lg">
                                <div class="grid grid-cols-3 gap-2 text-center">
                                    <div class="bg-indigo-100 p-2 rounded">8字节</div>
                                    <div class="bg-purple-100 p-2 rounded">4字节</div>
                                    <div class="bg-blue-100 p-2 rounded">8字节</div>
                                </div>
                                <div class="grid grid-cols-3 gap-2 text-center mt-1">
                                    <div class="text-sm">消息物理偏移量</div>
                                    <div class="text-sm">消息大小</div>
                                    <div class="text-sm">消息Tag哈希值</div>
                                </div>
                            </div>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2">异步构建机制</h4>
                            <ul class="text-gray-600 space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-indigo-500 mt-1 mr-2"></i>
                                    <span>ReputMessageService线程负责从CommitLog读取消息，构建ConsumeQueue和IndexFile</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-indigo-500 mt-1 mr-2"></i>
                                    <span>通过CommitLog的消费进度(reputFromOffset)确定下一个要处理的消息</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-arrow-right text-indigo-500 mt-1 mr-2"></i>
                                    <span>采用批量处理方式，提高构建效率</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Message Index Implementation -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-2 h-8 bg-indigo-600 mr-4 rounded-full"></div>
                <h2 class="text-3xl font-bold">消息索引的实现机制</h2>
            </div>

            <!-- Index File Structure -->
            <div class="bg-white rounded-xl shadow-md p-6 mb-8 card-hover">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-file-alt text-blue-500 mr-2"></i>
                    索引文件结构
                </h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <!-- File Header -->
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2">文件头 (40字节)</h4>
                        <div class="bg-gray-50 p-3 rounded-lg">
                            <ul class="text-sm text-gray-600 space-y-1">
                                <li>索引文件创建时间</li>
                                <li>最后更新时间</li>
                                <li>索引条目数量</li>
                                <li>其他元信息</li>
                            </ul>
                        </div>
                    </div>
                    <!-- Hash Slot -->
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2">哈希槽 (默认500万)</h4>
                        <div class="bg-gray-50 p-3 rounded-lg">
                            <ul class="text-sm text-gray-600 space-y-1">
                                <li>每个槽4字节</li>
                                <li>存储指向索引条目的指针</li>
                                <li>用于快速定位索引条目</li>
                            </ul>
                        </div>
                    </div>
                    <!-- Index Entry -->
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2">索引条目 (20字节)</h4>
                        <div class="bg-gray-50 p-3 rounded-lg">
                            <div class="grid grid-cols-2 gap-2 mb-1">
                                <div class="bg-blue-100 p-1 rounded text-xs text-center">4字节</div>
                                <div class="text-xs">消息Key哈希码</div>
                            </div>
                            <div class="grid grid-cols-2 gap-2 mb-1">
                                <div class="bg-blue-100 p-1 rounded text-xs text-center">8字节</div>
                                <div class="text-xs">消息物理偏移量</div>
                            </div>
                            <div class="grid grid-cols-2 gap-2 mb-1">
                                <div class="bg-blue-100 p-1 rounded text-xs text-center">4字节</div>
                                <div class="text-xs">时间戳差值</div>
                            </div>
                            <div class="grid grid-cols-2 gap-2">
                                <div class="bg-blue-100 p-1 rounded text-xs text-center">4字节</div>
                                <div class="text-xs">下一个条目位置</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Index Process -->
            <div class="grid md:grid-cols-2 gap-6">
                <!-- Build Process -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-wrench text-orange-500 mr-2"></i>
                        索引构建过程
                    </h3>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">触发时机</h4>
                            <ul class="text-gray-600 space-y-2 text-sm">
                                <li class="flex items-start">
                                    <i class="fas fa-clock text-blue-500 mt-1 mr-2"></i>
                                    <span>消息写入CommitLog后，由ReputMessageService异步构建</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-toggle-on text-blue-500 mt-1 mr-2"></i>
                                    <span>可配置是否开启索引功能</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">索引Key选择</h4>
                            <ul class="text-gray-600 space-y-2 text-sm">
                                <li class="flex items-start">
                                    <i class="fas fa-key text-blue-500 mt-1 mr-2"></i>
                                    <span>默认使用消息的KEYS属性作为索引Key</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-keyboard text-blue-500 mt-1 mr-2"></i>
                                    <span>一个消息可以有多个Key，以空格分隔</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-link text-blue-500 mt-1 mr-2"></i>
                                    <span>每个Key都会创建独立的索引条目</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">哈希冲突处理</h4>
                            <ul class="text-gray-600 space-y-2 text-sm">
                                <li class="flex items-start">
                                    <i class="fas fa-random text-blue-500 mt-1 mr-2"></i>
                                    <span>采用链表法解决哈希冲突</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-project-diagram text-blue-500 mt-1 mr-2"></i>
                                    <span>当多个Key哈希到同一个槽时，通过next字段形成链表</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Query Process -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-search text-green-500 mr-2"></i>
                        索引查询过程
                    </h3>
                    <div class="space-y-6">
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">按Key查询</h4>
                            <ol class="text-gray-600 space-y-2 text-sm">
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">1</span>
                                    <span>计算Key的哈希值</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">2</span>
                                    <span>定位到对应的哈希槽</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">3</span>
                                    <span>遍历链表，比较完整的Key</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-blue-100 text-blue-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">4</span>
                                    <span>找到匹配的条目后，从CommitLog读取消息</span>
                                </li>
                            </ol>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-700 mb-2">按时间范围查询</h4>
                            <ol class="text-gray-600 space-y-2 text-sm">
                                <li class="flex items-start">
                                    <span class="bg-green-100 text-green-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">1</span>
                                    <span>根据时间范围选择合适的索引文件</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-green-100 text-green-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">2</span>
                                    <span>遍历索引条目，筛选时间在范围内的条目</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="bg-green-100 text-green-800 rounded-full w-5 h-5 flex items-center justify-center mr-2 flex-shrink-0">3</span>
                                    <span>根据物理偏移量从CommitLog中读取消息</span>
                                </li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-indigo-50 rounded-xl p-8 mb-16">
            <div class="flex items-start">
                <div class="bg-indigo-100 p-3 rounded-full mr-4">
                    <i class="fas fa-lightbulb text-indigo-600 text-xl"></i>
                </div>
                <div>
                    <h3 class="text-2xl font-semibold text-indigo-800 mb-4">设计总结</h3>
                    <p class="text-gray-700 mb-4">
                        RocketMQ的存储设计充分考虑了性能、可靠性和可扩展性，通过CommitLog、ConsumeQueue和IndexFile的协同工作，实现了高效的消息存储和查询功能。这种分离存储与索引的设计，既保证了写入性能，又优化了读取效率，为消息中间件的高性能运行提供了坚实的基础。
                    </p>
                    <div class="grid md:grid-cols-3 gap-4">
                        <div class="bg-white p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <div class="w-2 h-2 bg-indigo-600 rounded-full mr-2"></div>
                                <h4 class="font-medium">高性能</h4>
                            </div>
                            <p class="text-sm text-gray-600">顺序写入+异步索引构建，最大化I/O性能</p>
                        </div>
                        <div class="bg-white p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <div class="w-2 h-2 bg-indigo-600 rounded-full mr-2"></div>
                                <h4 class="font-medium">高可靠</h4>
                            </div>
                            <p class="text-sm text-gray-600">CommitLog完整存储，支持故障后索引重建</p>
                        </div>
                        <div class="bg-white p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <div class="w-2 h-2 bg-indigo-600 rounded-full mr-2"></div>
                                <h4 class="font-medium">可扩展</h4>
                            </div>
                            <p class="text-sm text-gray-600">多级索引结构支持海量消息的高效查询</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-1">技术小馆</h3>
                    <p class="text-sm">深入技术细节，探索架构之美</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-300 hover:text-white transition-colors duration-200 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        <span>www.yuque.com/jtostring</span>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-6 pt-6 text-sm text-center text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            sequence: {
                diagramMarginX: 50,
                diagramMarginY: 10,
                boxTextMargin: 5,
                noteMargin: 10,
                messageMargin: 35,
                mirrorActors: true
            }
        });
        
        // 添加微交互效果
        document.querySelectorAll('.card-hover').forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.boxShadow = '0 25px 50px -12px rgba(0, 0, 0, 0.25)';
            });
            card.addEventListener('mouseleave', function() {
                this.style.boxShadow = '';
            });
        });
    </script>
</body>
</html>
```